﻿@inject IHttpService _httpService

<CnGalWebSite.Shared.MasaComponent.Shared.Cards.TitleTip NoIndex Title="@(Model.Type.GetDisplayName() +" "+(string.IsNullOrWhiteSpace(Model.ObjectName) ? ("Id：" + Model.ObjectId) : Model.ObjectName)+(Model.IsPassed==null?" 审核":" 编辑") )"/>


<div>
    @if (isReady == false)
    {
        <CnGalWebSite.Components.Progressings.ProgressingCard Page />
    }
    else
    {
        @if (Model.PrepositionExamineId > 0)
        {
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert Type="AlertTypes.Error" Class="mb-4">
                当前审核拥有一个前置审核，请先<a class="error--text fw-bold" @onclick="ExaminePrepositionExamine">审核</a>其前置审核
            </CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert>
        }
        <div>
            <CnGalWebSite.Shared.Component.Admin.Examines.Cards.TitleCard Model="Model" Class="mb-4"/>
            <CnGalWebSite.Shared.Component.Admin.Examines.Cards.StepCard Model="Model"  Class="mb-4"/>
            <CnGalWebSite.Shared.Component.Admin.Examines.Cards.OverviewCard Model="Model" Class="mb-4" />
            <div class="row">
                <div class="col-12 col-lg-6">
                    <CnGalWebSite.Components.Containers.MasaTitleContainer Icon="@IconType.Key.ToIconString()" Title="@(Model.IsPassed==null? "修改前" : "编辑后")" Class="mb-4" Collapable Outline>
                        <CnGalWebSite.Shared.Component.Admin.Examines.Cards.PreViewCard Model="Model.BeforeModel"/>
                    </CnGalWebSite.Components.Containers.MasaTitleContainer>

                </div>
                <div class="col-12 col-lg-6">
                 <CnGalWebSite.Components.Containers.MasaTitleContainer Icon="@IconType.Lock.ToIconString()" Title="@(Model.IsPassed==null? "修改后" : "当前状态")" Class="mb-4" Collapable Outline>
                        <CnGalWebSite.Shared.Component.Admin.Examines.Cards.PreViewCard Model="Model.AfterModel" />
                    </CnGalWebSite.Components.Containers.MasaTitleContainer>

                </div>
            </div>
          
                @if (Model.IsPassed == null && Model.PrepositionExamineId <= 0&&Model.IsAdmin)
                {
                    <CnGalWebSite.Shared.Component.Admin.Examines.Cards.SubmitCard Model="Model"  Class="mb-4"/>
                }
        </div>
    }
</div>


@code {
    [SupplyParameterFromQuery]
    [Parameter]
    public long Id { get; set; }

    public ExamineViewModel Model { get; set; } = new ExamineViewModel();
    private string Title { get; set; }

    private bool isReady = false;
    private bool isFirst = true;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            try
            {

                //获取审核信息
                Model = await _httpService.GetAsync<ExamineViewModel>("api/examines/GetExamineView/" + Id);

                isReady = true;
                StateHasChanged();
            }
            catch (Exception ex)
            {
                await ErrorHandler.ProcessError(ex, "获取审核信息失败");
            }
        }
    }

    private async Task ExaminePrepositionExamine()
    {
        isReady = false;
        isFirst = true;
        Id = Model.PrepositionExamineId;
        StateHasChanged();
        await OnInitializedAsync();
    }
}
